/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:18:37
 * @LastEditTime: 2021-12-06 17:36:29
 * @LastEditors: 赵大壮
 */
import { Component, Vue, Inject } from "vue-property-decorator";
import DZServiceRule from "../../service/DZServiceRule";
import UiDialogAddRule from "@/components/ui-dialog/UiDialogAddRule.vue"
import UiDialogAddRuleResult from "@/components/ui-dialog/UiDialogAddRuleResult.vue"
import DZModelRule from "../../model/DZModelRule";
import DZModelRuleResult from "../../model/DZModelRuleResult";
import dzMsgBox from "@/utils/DZMessageBox";

@Component({
    components: { UiDialogAddRule, UiDialogAddRuleResult }
})
export default class Index extends Vue {

    s_rule = new DZServiceRule();

    dialog_add_rule = false;

    dialog_add_rule_result = false;

    created() { }

    mounted() {
        this.s_rule.assess = this.$route.query.id as string;
        this.action_list_rule();
    }

    beforeDestroy() {

    }
    action_go_back() {
        this.$router.push({ path: this.$route.query.father as string })
    }

    action_list_rule() {
        this.s_rule.net_list_rule();
    }

    action_edit_rule(item) {
        this.s_rule.m_rule = JSON.parse(JSON.stringify(item));
        this.dialog_add_rule = true;
    }

    action_add_rule(data) {
        this.dialog_add_rule = false;
        this.s_rule.m_rule = JSON.parse(JSON.stringify(data));
        if (data.id) {
            this.s_rule.net_edit_rule(() => {
                this.s_rule.m_rule = new DZModelRule();
                this.action_list_rule();
            });
        } else {
            this.s_rule.net_add_rule(() => {
                this.s_rule.m_rule = new DZModelRule();
                this.action_list_rule();
            });
        }
    }

    action_list_result() {
        this.s_rule.net_list_rule_result();
    }

    action_rule_table_item_click(row, column, event) {
        this.s_rule.m_rule = row;
        this.action_list_result();
    }

    action_add_rule_result(data: DZModelRuleResult) {
        this.dialog_add_rule_result = false;
        this.s_rule.m_result = JSON.parse(JSON.stringify(data))
        if (data.id) {
            this.s_rule.net_edit_rule_result(() => {
                this.s_rule.m_result = new DZModelRuleResult();
                this.action_list_result();
            });
        } else {
            this.s_rule.net_add_rule_result(() => {
                this.s_rule.m_result = new DZModelRuleResult();
                this.action_list_result();
            });
        }
    }
    action_edit_rule_result(item) {
        this.s_rule.m_result = JSON.parse(JSON.stringify(item))
        this.dialog_add_rule_result = true;
    }

    action_del_rule_result(item) {
        dzMsgBox.del("是否删除该结果", () => {
            this.s_rule.net_del_rule_result(item.id, () => {
                this.action_list_result();
            })
        })
    }

}